<?php
$posts = $args['posts'] ?? [];
$pagesize = $args['pagesize'] ?? 8;

if (empty($posts)) {
    $posts = get_random_posts($pagesize);
}
?>
<div class="ctimgpost1">
    <section class="imgpost1">
        <?php
        foreach ($posts as $post) {
        ?>
            <a href="<?= $post['link'] ?>" title="<?= $post['title'] ?>">
                <img src="<?= $post['thumbnail'] ?>" alt="<?= $post['title'] ?>">
                <section class="grid">
                    <h3 class="nowrap2"><?= $post['title'] ?></h3>
                    <span><?= $post['date'] ?> </span>
                    <p><?= $post['excerpt'] ?></p>
                </section>
            </a>
        <?php
        }
        ?>
    </section>
</div>
<style>
    div.ctimgpost1 {
        container-type: inline-size;
        container-name: imgpost1;
    }

    section.imgpost1 {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: var(--gap);
    }

    section.imgpost1>a {
        transition: var(--transition);
        background-color: var(--color-primary);
    }

    section.imgpost1>a>img {
        width: 100%;
        height: 16rem;
    }

    section.imgpost1>a>section {
        padding: var(--gap);
    }

    section.imgpost1>a>img,
    section.imgpost1>a>section>h3,
    section.imgpost1>a>section>span,
    section.imgpost1>a>section>p {
        cursor: pointer;
    }

    section.imgpost1>a:hover {
        transform: scale(1.05);
        filter: brightness(1.2);
        border: 1px solid #ffbd41;
        box-shadow: 0px 4px 6px rgb(255, 189, 65, .2);
    }

    @container imgpost1 (max-width: 1200px) {
        section.imgpost1 {
            grid-template-columns: repeat(4, 1fr);
        }

        section.imgpost1>a>img {
            height: 12rem;
        }

    }

    @container imgpost1 (max-width: 1024px) {
        section.imgpost1 {
            grid-template-columns: repeat(3, 1fr);
        }
    }

    @container imgpost1 (max-width: 768px) {
        section.imgpost1 {
            grid-template-columns: repeat(2, 1fr);
        }
    }


    @container imgpost1 (max-width: 576px) {
        section.imgpost1 {
            grid-template-columns: auto;
        }

        section.imgpost1>a>img {
            height: 16rem;
        }
    }
</style>